package com.jaya.budan.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jaya.budan.R;
import com.jaya.budan.bean.User_Wallet;
import com.jaya.budan.utils.ToolUtils;

import java.util.List;

public class GV_Recharge_Item_Adapter extends BaseAdapter {

    private Context mcontext;
    private List<User_Wallet> mlist;
    private int select = -1, mtype;
    public GV_Recharge_Item_Adapter(Context context, List<User_Wallet> list, int type){
        mcontext = context;
        mlist = list;
        mtype = type;
    }

    public int getSelect() {
        return select;
    }

    public void setSelect(int select) {
        this.select = select;
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (mtype == 1){
            convertView = View.inflate(mcontext, R.layout.gv_recharge_item, null);
            LinearLayout ll_recharge_item = convertView.findViewById(R.id.ll_recharge_item);
            TextView tv_recharge_item_1 = convertView.findViewById(R.id.tv_recharge_item_1);
            TextView tv_recharge_item_2 = convertView.findViewById(R.id.tv_recharge_item_2);
            ImageView iv_recharge_item_1 = convertView.findViewById(R.id.iv_recharge_item_1);
            ImageView iv_recharge_item_choose = convertView.findViewById(R.id.iv_recharge_item_choose);
            tv_recharge_item_1.setText("" + ToolUtils.addComma(mlist.get(position).getYb() + ""));
            tv_recharge_item_2.setText(mlist.get(position).getMoney() + "元");
            if (mlist.get(position).getStatus() == 0){
                tv_recharge_item_1.setVisibility(View.GONE);
                iv_recharge_item_1.setVisibility(View.GONE);
                tv_recharge_item_2.setText("其他金额");
            }
            if (position == select){
                iv_recharge_item_choose.setVisibility(View.VISIBLE);
                ll_recharge_item.setBackgroundResource(R.drawable.gv_item_recharge_choose);
            } else {
                iv_recharge_item_choose.setVisibility(View.INVISIBLE);
                ll_recharge_item.setBackgroundResource(R.drawable.gv_item_recharge);
            }
        } else {
            convertView = View.inflate(mcontext, R.layout.gv_recharge_item2, null);
            LinearLayout ll_recharge_item = convertView.findViewById(R.id.ll_recharge_item);
            TextView tv_recharge_item_1 = convertView.findViewById(R.id.tv_recharge_item_1);
            TextView tv_recharge_item_2 = convertView.findViewById(R.id.tv_recharge_item_2);
            tv_recharge_item_1.setText(mlist.get(position).getName().substring(0, mlist.get(position).getName().length()-2) + "");
            if (position == select){
                tv_recharge_item_1.setTextColor(Color.parseColor("#FF3B30"));
                tv_recharge_item_2.setTextColor(Color.parseColor("#FF3B30"));
                ll_recharge_item.setBackgroundResource(R.drawable.gv_item_recharge_choose);
            } else {
                tv_recharge_item_1.setTextColor(Color.parseColor("#999999"));
                tv_recharge_item_2.setTextColor(Color.parseColor("#999999"));
                ll_recharge_item.setBackgroundResource(R.drawable.gv_item_recharge);
            }
        }
        return convertView;
    }
}